﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyCityCab.Core
{
    public partial class City
    {
        public static City GetOrCreate(string cityName, int countryId)
        {
            SubSonic.Query query = City.CreateQuery();
            CityCollection coll = new CityCollection();
            query.WHERE(City.Columns.EnglishName, cityName).AND(City.Columns.CountryId, countryId);
            query.Top = "1";
            coll.LoadAndCloseReader(query.ExecuteReader());
            if (coll.Count > 0)
                return coll[0];
            City city = new City();
            city.CountryId = countryId;
            city.EnglishName = cityName;
            city.Save();
            return city;
        }
    }
}
